package org.smr.ministore.controller;

import javax.annotation.Resource;

import org.blade.msg.Message;
import org.blade.utils.Pager;
import org.smr.ministore.entities.DictionaryOrgan;
import org.smr.ministore.service.DictionaryOrganService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;


@Controller("DictionaryOrganController")
public class DictionaryOrganController {

	@Resource
	private DictionaryOrganService service;
	
	/**
	 * 保存编辑后的DictionaryOrgan信息
	 * @param DictionaryOrgan
	 * @return
	 */
	@ResponseBody
	@RequestMapping(method = RequestMethod.PATCH, value = "/DictionaryOrgan/edit")
	public Message modify(@RequestBody DictionaryOrgan DictionaryOrgan){
		Message msg = new Message();
		
		if(null == DictionaryOrgan.getId()){
			msg.setStatus(service.save(DictionaryOrgan));
		}else{
			msg.setStatus(service.updateById(DictionaryOrgan));
		}
		return msg;
	}
	
	/**
	* 跳转到列表查询DictionaryOrgan
	 * @return
	 */
	@RequestMapping(method = RequestMethod.GET, value = "/DictionaryOrgan/list-page")
	public String toList(){
		return "/DictionaryOrgan/DictionaryOrgan-list";
	}

	/**
	*  根据id查询DictionaryOrgan
	* @return
	*/
	@ResponseBody
	@RequestMapping(method = RequestMethod.GET, value = "/DictionaryOrgan")
	public DictionaryOrgan get( Long id ){
		return service.queryById(id);
	}


    /**
	 * 分页查询DictionaryOrgan信息
	 * @param DictionaryOrgan
	 * @param pageSize
	 * @param pageNum
	 * @return
	 */
	@ResponseBody
	@RequestMapping( value = "/DictionaryOrgan/list")
	public Pager<DictionaryOrgan> list(@RequestBody DictionaryOrgan DictionaryOrgan , long pageSize, long pageNum ){

		return service.paginate(DictionaryOrgan, pageSize, pageNum);

	}
	
	
	/**
	 * 根据ID删除DictionaryOrgan信息
	 * @param id
	 * @return
	 */
	@ResponseBody
	@RequestMapping( value = "/DictionaryOrgan/remove",method = RequestMethod.DELETE)
	public Message remove( Long id){
		
		Message msg = new Message();
		msg.setStatus(service.deleteById(id));
		return msg;
	}

    /**
     * 指定可使用字典
     * @param dictionaryOrganList
     * @param organId
     * @return
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.PUT, value = "/DictionaryOrgan/assignedDictionary/{organId}")
    public Message assignedDictionary(@RequestBody List<DictionaryOrgan> dictionaryOrganList, @PathVariable("organId") Long organId){

        Message msg = new Message();
        msg.setStatus(service.assignedDictionary(dictionaryOrganList, organId));
        return msg;
    }

}
